/**
 * Copyright (c) 2011-2012
 * OmniCore CodeGuide
 */
package de.tum.in.oose.bumpers;

import java.applet.Applet;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.net.URL;

import javax.swing.JPanel;

import de.tum.in.oose.bumpers.cars.Car;
import de.tum.in.oose.bumpers.cars.UserCar;
import de.tum.in.oose.bumpers.cars.FastCar;
import de.tum.in.oose.bumpers.cars.SlowCar;
import de.tum.in.oose.bumpers.cars.instruments.SpeedController;
import de.tum.in.oose.bumpers.control.Referee;
import de.tum.in.oose.bumpers.ui.Game;


/**
 * Class for Starting the Game.
 */
public final class Start {
	
	/**
	 * Standard constr.
	 */
	private Start()	{
		super();
	}
	
	/**
	 * The Main method for starting the game.
	 * @param args - string args
	 */
	public static void main(String[] args) {
		
		try {
			Car.setDefaultImage(loadImage("FastCar.gif"));
			UserCar.setDefaultImage(loadImage("A-Klasse.gif"));
			FastCar.setDefaultFastCarImage(loadImage("SLK.gif"));
			SlowCar.setDefaultSlowCarImage(loadImage("Kaefer.gif"));
			SpeedController.setUp(loadImage("up.gif"));
			SpeedController.setDown(loadImage("down.gif"));
			Referee.setMusic(Applet.newAudioClip(Start.class.getResource("Music.au")));
			Referee.setBang(Applet.newAudioClip(Start.class.getResource("Bang.au")));
			
		} catch (InterruptedException e) {
			e.printStackTrace();
			System.exit(-1);
		}
		
		
		
		Game bumperWindow = new Game();
		bumperWindow.pack();
		bumperWindow.setVisible(true);
	}
	
	/**
	 * @param name the name of the image to be loaded
	 * @return the created image
	 * @throws InterruptedException -
	 */
	public static Image loadImage(String name) throws InterruptedException  {
		URL url = Start.class.getResource(name);
		MediaTracker m = new MediaTracker(new JPanel());
		Image img = Toolkit.getDefaultToolkit().getImage(url);
		m.addImage(img, 0);
		m.waitForAll();
		return img;
	}
	
}


